<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./animate.min.css">
    <style>
        div {
            height: 600px;
            box-sizing: border-box;
        }
        #first {
            display: flex;
            /* background-color: antiquewhite; */
            border-radius: 15px;
            width: 1200px;
            margin: 30px auto;
            flex-wrap: wrap;
            justify-content: center;
        }
        #first div {
            margin: 5px 5px;
            width: 500px;
            border-radius: 15px;
            height: 290px;
            border: 2px solid transparent;
            background-color: turquoise;
        }
    
    </style>
    <script src="./jquery-3.6.0.js"></script>
    <script>
        $(function(){
            $(window).scroll(function(){
                // 浏览器已经滚动过的高度
            //     console.log($(document).scrollTop());
            //     // 屏幕的可视区域高度
            //    console.log($(window).height());
                // 元素到文档顶部的距离
            //    console.log($(".animated").offset().top); 
                var domheight = $("#first").offset().top;
                var height = $(document).scrollTop()+$(window).height();
                // console.log(domheight);
                // console.log(height);
                // domheight = domheight.toString();
                // height = height.toString();
                // if(domheight.substring(0,domheight.indexOf('.')) - height.substring(0,height.indexOf('.')) == 0){
                //     console.log(1);
                // }
                if((height-domheight) > 200&&$(document).scrollTop()<(domheight+$("#first").height())){
                    ani();
                }
            });

            function ani(){
                //原理：使用静态成员
             if(!ani.flag){
                
                $("#first div").each(function(){
                    $(this).addClass("bounceIn");
                });

                ani.flag = 1;
             };
                
            }
        });
    </script>
</head>
<body>
    <div></div>
    <div></div>
    <div></div>
    <div id="first">
        <div class="animated"></div>
        <div class="animated"></div>
        <div class="animated"></div>
        <div class="animated"></div>
    </div>
    <div></div>
    <div></div>
</body>
</html>